#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time    : 2021/8/7 19:28
# @Author  : 李中华
# @Email   : 1260429766@qq.com
# @File    : resultChange.py
class ResultChange:
    def resultchange(self,param,final_param):
        '''
        合并关联参数和param值
        :param 参数中带$
        :final_param 字典类型,值更新到param中:
        :return:
        '''
        temp_dict = {}
        param = eval(param)
        if isinstance(param,dict):
            for key in final_param.keys():
                if key in param:
                    temp_dict[key] = final_param[key]
            param.update(temp_dict)
        param = str(param)
        return param

    def resultchangeURL(self,rl,final_param):
        '''
        参数替换到url中
        :param rl excel表格中的rl，带$符:
        :param final_param 字典类型的参数，替换到rl中:
        :return:
        '''
        rl = rl.split('/')
        for i in range(0,len(rl)):
            for paramKey in final_param.keys():
                if rl[i] == '$' + paramKey:
                    rl[i] = final_param[paramKey]
        rl = '/'.join(rl)
        return rl

if __name__ == '__main__':
    params = '{"robotId": "11","key":"33"}'
    param = '''/api/robotTask/$robotId/$key'''
    final_param = {"robotId": "4d472b34ab084aa4a6fb3e954bf33420","execStatus": 2,'key':'value'}
    # print(ResultChange().resultchange(params,final_param))
    print(type(ResultChange().resultchangeURL(param,final_param)))
